home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / SBSIMDMO / DRVRFUNC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-20  |  18.6 KB  |  620 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include "drvrfunc.h"
  4.  
  5. int SIMint;  // Interrupt used to access SBSIM
  6.  
  7. /*--- SBSIM error messages ------------------*/
  8. char *errorMsg[] = {NULL,
  9.             "SBSIM currently in use",
  10.             "Bad driver specified",
  11.             "Bad function specified",
  12.             "Voice process is already active",
  13.             "Couldn't start CT-VOICE",
  14.             "Couldn't start CTVDSK",
  15.             "Invalid SBSIM handle",
  16.             "Buffer not initialized yet",
  17.             "Bad file name for load",
  18.             "Bad file handle",
  19.             "Driver not started yet",
  20.             "XMS driver not installed",
  21.             "No free SBSIM handles",
  22.             "Bad file type specified",
  23.             "Couldn't free XMS block",
  24.             "Invalid source selected",
  25.             "Get-Pan-Position failed",
  26.             "Set-Pan-Position failed",
  27.             "Set-Volume failed",
  28.             "Couldn't start fade/pan",
  29.             "Couldn't stop fade/pan",
  30.                 "Couldn't pause fade/pan",
  31.             "Not a fade/pan operation",
  32.             "Bad mode for fade/pan",
  33.                 "Couldn't start fade/pan",
  34.             "Source not fading/panning",
  35.                 "FM or MIDI already playing",
  36.                 "Bad MIDI mapper format"};
  37.  
  38. /*************************************************************************
  39. *
  40. * FUNCTION: FINDDVR - Searches for the requested driver's interrupt number
  41. *                     by looking for IDStr (in theis case it will be
  42. *                     SBSIM) in the interrupt vector table memory at the
  43. *                     offset (as in SEGMENT:OFFSET) location passed to
  44. *                     this function.
  45. *
  46. * Inputs: IDStr - driver ID string (i.e. "SBSIM").
  47. *         IDOff - driver's ID offset.
  48. *
  49. * Output: interrupt number or 0 (error condition) if not found.
  50. *
  51. *************************************************************************/
  52. unsigned FindDvr(char *IDStr, unsigned int IDOff)
  53. {
  54.     unsigned dvrInt,
  55.     intFound = FALSE;
  56.     char far *far *dvrVec;
  57.  
  58.     for(dvrInt = 0x80; (dvrInt < 0x0C0) && (intFound == FALSE); ++ dvrInt)
  59.   {
  60.     dvrVec = MK_FP(0, dvrInt * 4);
  61.     if(!_fstrncmp((char far *)MK_FP(FP_SEG(*dvrVec), IDOff), IDStr,
  62.        sizeof(IDStr)))
  63.     {
  64.       intFound = TRUE;
  65.     }
  66.   }
  67.  
  68.   if(intFound == TRUE)
  69.     return(--dvrInt);
  70.  
  71.   return(0);
  72. }
  73.  
  74. /*************************************************************************
  75. *
  76. * FUNCTION: GETDVRINFO - Get status, entry point, buffer location, and
  77. *                        buffer size from SBSIM.  The DVRINFO struct gets
  78. *                        loaded with this information
  79. *
  80. * Inputs: driver - driver to get info on.
  81. *         *dvrInfo - pointer to DVRINFO structure.
  82. *
  83. * Output: status - the driver's status.
  84. *
  85. * note: requires SIMint be defined before calling.
  86. *
  87. *************************************************************************/
  88. int GetDvrInfo(DRIVER driver, DVRINFO *dvrInfo)
  89. {
  90.   int dvrLoc;
  91.  
  92.   dvrLoc = 1 << driver;
  93.   if(GetDrvrs() & dvrLoc)
  94.   {
  95.         dvrInfo->status = LOADED;
  96.         GetAddress(driver, &dvrInfo->entry);
  97.     if(GetBufInfo(driver, &dvrInfo->bufLoc, &dvrInfo->bufSize) != SIMerr_NoErr)
  98.     {
  99.       dvrInfo->bufLoc = 0;
  100.       dvrInfo->bufSize = 0;
  101.     }
  102.   }
  103.   else
  104.     dvrInfo->status = MISSING;
  105.  
  106.   return(dvrInfo->status);
  107. }
  108.  
  109. /*************************************************************************
  110. *
  111. * FUNCTION: VERSION - Get the current version of SBSIM.
  112. *
  113. * Inputs: none
  114. *
  115. * Output: version = high byte, sub-version = low byte.
  116. *
  117. * note: requires SIMint be defined before calling.
  118. *
  119. *************************************************************************/
  120. unsigned Version(void)
  121. {
  122.   union REGS inregs,
  123.          outregs;
  124.  
  125.   inregs.h.bh = 0;  // control function
  126.   inregs.h.bl = 0;  // query version sub-fn
  127.     int86(SIMint, &inregs, &outregs);
  128.   return(outregs.x.ax); // return version number
  129. }
  130.  
  131. /*************************************************************************
  132. *
  133. * FUNCTION: GETDRVRS - Determines which drivers are loaded.
  134. *
  135. * Inputs: none
  136. *
  137. * Output: bit field indicating which drivers are loaded.
  138. *
  139. *         bit 0 - FM driver
  140. *         bit 1 - Double disk buffered voice driver
  141. *         bit 2 - Memory voice driver
  142. *         bit 3 - Auxiliary driver (mixer)
  143. *         bit 4 - MIDI driver
  144. *
  145. * note: requires SIMint be defined before calling.
  146. *
  147. *************************************************************************/
  148. unsigned GetDrvrs(void)
  149.  {
  150.    union REGS inregs, outregs;
  151.  
  152.    inregs.h.bh = 0;  // control function
  153.    inregs.h.bl = 1;  // query drivers sub-fn
  154.    int86(SIMint, &inregs, &outregs);
  155.    return(outregs.x.ax);  // return driver bit field
  156. }
  157.  
  158. /*************************************************************************
  159. *
  160. * FUNCTION: GETADDRESS - Returns selected driver's entry address.
  161. *
  162. * Inputs: driver   0 - FM driver
  163. *                  1 - Double disk buffered voice driver
  164. *                  2 - Memory voice driver
  165. *                  3 - Auxiliary driver (mixer)
  166. *                  4 - MIDI driver
  167. *                  *address - storage for entry address pointer
  168. *
  169. * Output: 0 if no error.
  170. *
  171. * note: requires SIMint be defined before calling.
  172. *
  173. *************************************************************************/
  174. SIMERR GetAddress(DRIVER driver, long *address)
  175. {
  176.     union REGS inregs, outregs;
  177.  
  178.     inregs.h.bh = 0;  // control function
  179.     inregs.h.bl = 2;  // driver entry address sub-fn
  180.     inregs.x.ax = driver;
  181.     int86(SIMint, &inregs, &outregs);
  182.     *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
  183.     if(!outregs.x.cflag)      // test for errors
  184.         return(0);            // return result
  185.  
  186.     return(outregs.x.ax); // error occured
  187. }
  188.  
  189. /*************************************************************************
  190. *
  191. * FUNCTION: GETBUFINFO - Returns selected driver's buffer address.
  192. *
  193. * Inputs: driver   0 - FM driver
  194. *                  1 - Double disk buffered voice driver
  195. *                  4 - MIDI driver
  196. *                  *address - pointer to storage for buffer address pointer
  197. *                  *size - pointer storage for size of buffer (in Kbytes)
  198. *
  199. * Output: 0 if no error
  200. *
  201. * note: requires SIMint be defined before calling.
  202. *
  203. *************************************************************************/
  204. SIMERR GetBufInfo(DRIVER driver, long *address, unsigned *size)
  205. {
  206.     union REGS inregs, outregs;
  207.  
  208.     inregs.h.bh = 0;  // control function
  209.     inregs.h.bl = 5;  // driver entry address sub-fn
  210.     inregs.x.ax = driver;
  211.     int86(SIMint, &inregs, &outregs);
  212.   *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
  213.   *size = outregs.x.cx;  // return buffer size
  214.   if(!outregs.x.cflag)     // test for errors
  215.         return(0);           // No error
  216.  
  217.   return(outregs.x.ax);  // error occured
  218. }
  219.  
  220. /*************************************************************************
  221. *
  222. * FUNCTION: STARTSND - Initializes the driver for output.
  223. *
  224. * Inputs: driver:  0 - FM driver
  225. *                  1 - Double disk buffered voice driver
  226. *                  2 - Memory voice driver
  227. *                  4 - MIDI driver
  228. *         *ptr - pointer to filename or memory location.
  229. *
  230. *         type: EXTENDED_MEM_VOD - Play a .VOC file from extended
  231. *                                  memory.  #defined in DVRVFUNC.H
  232. *               NULL - Anything except a .VOC file from extended memory
  233. *
  234. *         SBSIMHandle - value obtained by LoadExtMem() if using extended
  235. *                       memory; any value if not.
  236. *
  237. * Output: Initialization result
  238. *
  239. * note: requires SIMint be defined before calling.
  240. *
  241. *************************************************************************/
  242. SIMERR StartSnd(DRIVER driver, void far *ptr, char type, int SBSIMHandle)
  243. {
  244.   union REGS inregs, outregs;
  245.  
  246.   inregs.h.bh = driver + 1;
  247.   inregs.h.bl = 0;            // start sound source function
  248.   inregs.x.cx = 0;
  249.   if (type == EXTENDED_MEM_VOC)
  250.   {
  251.     inregs.x.ax = SBSIMHandle;
  252.     inregs.x.dx = 0;
  253.   }
  254.     else  //  NOT EXTENDED MEMORY .VOC FILE
  255.     {
  256.     inregs.x.ax = FP_OFF(ptr);  // pointer to filename or data buffer
  257.     inregs.x.dx = FP_SEG(ptr);
  258.   }
  259.   int86(SIMint, &inregs, &outregs);
  260.   return(outregs.x.ax);       // return initialization result
  261. }
  262.  
  263. /*************************************************************************
  264. *
  265. * FUNCTION: GETSNDSTAT - Get the driver's status.
  266. *
  267. * Inputs: driver   0 - FM driver
  268. *                  1 - Double disk buffered voice driver
  269. *                  2 - Memory voice driver
  270. *                  4 - MIDI driver
  271. *
  272. * Output: Current status
  273. *
  274. * note: requires SIMint be defined before calling.
  275. *
  276. * RETURNS: -1 (negative one) if still playing
  277. *           0 (zero) if done playing
  278. *
  279. *************************************************************************/
  280. unsigned GetSndStat(DRIVER driver)
  281. {
  282.   union REGS inregs, outregs;
  283.  
  284.     inregs.h.bh = driver + 1;
  285.   inregs.h.bl = 5;       // get sound status function
  286.   inregs.x.cx = 0;
  287.   int86(SIMint, &inregs, &outregs);
  288.   return(outregs.x.ax);  // return status
  289. }
  290.  
  291. /*************************************************************************
  292. *
  293. * FUNCTION: PLAYSND - Plays music/voice on the selected driver.
  294. *
  295. * Inputs: driver   0 - FM driver
  296. *                  1 - Double disk buffered voice driver
  297. *                  2 - Memory voice driver
  298. *                  4 - MIDI driver
  299. *
  300. * Output: Result
  301. *
  302. * note: requires SIMint be defined before calling.
  303. *
  304. *************************************************************************/
  305. SIMERR PlaySnd(DRIVER driver)
  306. {
  307.   union REGS inregs, outregs;
  308.  
  309.   inregs.h.bh = driver + 1;
  310.   inregs.h.bl = 1;      // play sound function
  311.     inregs.x.cx = 0;
  312.     int86(SIMint, &inregs, &outregs);
  313.     return(outregs.x.ax); // return result
  314. }
  315.  
  316. /*************************************************************************
  317. *
  318. * FUNCTION: STOPSND - Stops music/voice on the selected driver.
  319. *
  320. * Inputs: driver   0 - FM driver
  321. *                  1 - Double disk buffered voice driver
  322. *                  2 - Memory voice driver
  323. *                  4 - MIDI driver
  324. *
  325. * Output: none
  326. *
  327. * note: requires SIMint be defined before calling.
  328. *
  329. *************************************************************************/
  330. void StopSnd(DRIVER driver)
  331. {
  332.     union REGS inregs, outregs;
  333.  
  334.     inregs.h.bh = driver + 1;
  335.     inregs.h.bl = 2;   // stop sound function
  336.     inregs.x.cx = 0;
  337.     int86(SIMint, &inregs, &outregs);
  338. }
  339.  
  340. /*************************************************************************
  341. *
  342. * FUNCTION: PAUSESND - Pauses music/voice on the selected driver.
  343. *
  344. * Inputs: driver   0 - FM driver
  345. *                  1 - Double disk buffered voice driver
  346. *                  2 - Memory voice driver
  347. *                  4 - MIDI driver
  348. *
  349. * Output: None
  350. *
  351. * note: requires SIMint be defined before calling.
  352. *
  353. *************************************************************************/
  354. void PauseSnd(DRIVER driver)
  355. {
  356.   union REGS inregs, outregs;
  357.  
  358.   inregs.h.bh = driver + 1;
  359.   inregs.h.bl = 3;    // pause sound function
  360.   inregs.x.cx = 0;
  361.   int86(SIMint, &inregs, &outregs);
  362. }
  363.  
  364. /*************************************************************************
  365. *
  366. * FUNCTION: RESUMESND - Continues paused music/voice.
  367. *
  368. * Inputs: driver   0 - FM driver
  369. *                  1 - Double disk buffered voice driver
  370. *                  2 - Memory voice driver
  371. *                  4 - MIDI driver
  372. *
  373. * Output: none
  374. *
  375. * note: requires SIMint be defined before calling.
  376. *
  377. *************************************************************************/
  378. void ResumeSnd(DRIVER driver)
  379. {
  380.   union REGS inregs, outregs;
  381.  
  382.   inregs.h.bh = driver + 1;
  383.   inregs.h.bl = 4;  // resume sound function
  384.   inregs.x.cx = 0;
  385.   int86(SIMint, &inregs, &outregs);
  386. }
  387.  
  388. /*************************************************************************
  389. *
  390. * FUNCTION: GETVOLUME - Get the source's volume.
  391. *
  392. * Inputs: source  0 - Master volume
  393. *                 1 - Voice volume
  394. *                 2 - MIDI volume
  395. *                 3 - CD volume
  396. *                 4 - Line-in volume
  397. *                 5 - Microphone volume
  398. *           *volume - source's volume returned in this variable
  399. *
  400. * Output: 0 if no error
  401. *
  402. * note: requires SIMint be defined before calling.
  403. *
  404. *************************************************************************/
  405. SIMERR GetVolume(SOURCE source, unsigned *volume)
  406. {
  407.   union REGS inregs, outregs;
  408.  
  409.   inregs.x.ax = source;
  410.     inregs.h.bh = 4;  // auxilary function
  411.   inregs.h.bl = 0;  // get source volume sub-function
  412.   int86(SIMint, &inregs, &outregs);
  413.   *volume = outregs.x.ax;  // return volume
  414.   if(outregs.x.cflag)
  415.     return(outregs.x.ax);  // return error code
  416.   return(0);
  417. }
  418.  
  419. /*************************************************************************
  420. *
  421. * FUNCTION: SETVOLUME - Set the source's volume.
  422. *
  423. * Inputs: source  0 - Master volume
  424. *                 1 - Voice volume
  425. *                 2 - FM volume
  426. *                 3 - CD volume
  427. *                 4 - Line-in volume
  428. *                 5 - Microphone volume
  429. *            volume - source's new volume
  430. *
  431. * Output: 0 if no error
  432. *
  433. * note: requires SIMint be defined before calling.
  434. *
  435. *************************************************************************/
  436. SIMERR SetVolume(SOURCE source, unsigned volume)
  437. {
  438.   union REGS inregs, outregs;
  439.  
  440.   inregs.h.bh = 4;  // auxilary function
  441.   inregs.h.bl = 1;  // set source volume sub-function
  442.   inregs.x.ax = source;
  443.   inregs.x.dx = volume;
  444.   int86(SIMint, &inregs, &outregs);
  445.     return(outregs.x.ax);
  446. }
  447.  
  448. /*************************************************************************
  449.  * FUNCTION: GETGAIN - Get the SB16's gain.
  450.  *
  451.  * Inputs: direction  0 - Input
  452.  *                    1 - Output
  453.  *         *level - storage for the gain's level
  454.  *                  MSB = left
  455.  *                  LSB = right
  456.  *
  457.  * Output: 0 if no error
  458.  *
  459.  * note: requires SIMint be defined before calling.
  460.  *************************************************************************/
  461. SIMERR GetGain(int direction, unsigned *level)
  462. {
  463.   union REGS inregs, outregs;
  464.  
  465.   inregs.x.ax = direction;
  466.   inregs.h.bh = 4;                    // auxilary function
  467.   inregs.h.bl = 2;                    // get gain sub-function
  468.   int86(SIMint, &inregs, &outregs);
  469.   *level = outregs.x.ax;              // return gain's level
  470.   if(outregs.x.cflag)
  471.     return(outregs.x.ax);             // return error code
  472.   else
  473.     return(0);
  474. }
  475.  
  476. /*************************************************************************
  477.  * FUNCTION: SETGAIN - Set the SB16's gain.
  478.  *
  479.  * Inputs: direction  0 - Input
  480.  *                    1 - Output
  481.  *         level - storage for the gain's level
  482.  *                 MSB = left
  483.  *                 LSB = right
  484.  *
  485.  * Output: 0 if no error
  486.  *
  487.  * note: requires SIMint be defined before calling.
  488.  *************************************************************************/
  489. SIMERR SetGain(int direction, unsigned level)
  490. {
  491.   union REGS inregs, outregs;
  492.  
  493.   inregs.x.ax = direction;
  494.   inregs.h.bh = 4;                    // auxilary function
  495.   inregs.h.bl = 3;                    // set gain sub-function
  496.   inregs.x.dx = level;                // gain's level
  497.   int86(SIMint, &inregs, &outregs);
  498.   if(outregs.x.cflag)
  499.     return(outregs.x.ax);             // return error code
  500.   else
  501.     return(0);
  502. }
  503.  
  504. /*************************************************************************
  505.  * FUNCTION: GETTONE - Get the SB16's tone.
  506.  *
  507.  * Inputs: band  0 - Treble
  508.  *               1 - Bass
  509.  *         *level - storage for the tone level
  510.  *                  MSB = left
  511.  *                  LSB = right
  512.  *
  513.  * Output: 0 if no error
  514.  *
  515.  * note: requires SIMint be defined before calling.
  516.  *************************************************************************/
  517. SIMERR GetTone(int band, unsigned *level)
  518. {
  519.   union REGS inregs, outregs;
  520.  
  521.   inregs.x.ax = band;
  522.   inregs.h.bh = 4;                    // auxilary function
  523.   inregs.h.bl = 4;                    // get tone sub-function
  524.   int86(SIMint, &inregs, &outregs);
  525.   *level = outregs.x.ax;              // return tone level
  526.   if(outregs.x.cflag)
  527.     return(outregs.x.ax);             // return error code
  528.   else
  529.     return(0);
  530. }
  531.  
  532. /*************************************************************************
  533.  * FUNCTION: SETTONE - Set the SB16's tone.
  534.  *
  535.  * Inputs: band  0 - Treble
  536.  *               1 - Base
  537.  *         level - storage for the gain's level
  538.  *                 MSB = left
  539.  *                 LSB = right
  540.  *
  541.  * Output: 0 if no error
  542.  *
  543.  * note: requires SIMint be defined before calling.
  544.  *************************************************************************/
  545. SIMERR SetTone(int band, unsigned level)
  546. {
  547.   union REGS inregs, outregs;
  548.  
  549.   inregs.x.ax = band;
  550.   inregs.h.bh = 4;                    // auxilary function
  551.   inregs.h.bl = 5;                    // set tone sub-function
  552.   inregs.x.dx = level;                // tone level
  553.   int86(SIMint, &inregs, &outregs);
  554.   if(outregs.x.cflag)
  555.     return(outregs.x.ax);             // return error code
  556.   else
  557.     return(0);
  558. }
  559.  
  560. /*************************************************************************
  561. *
  562. *
  563. * FUNCTION: LoadExtMem() - Load a .VOC file into extended memory.
  564. *
  565. * DESCRIPTION:  The parameter passed is far pointer to a null terminated
  566. *               string that contains the filename to be loaded into
  567. *               extended memory. (Example:  C:\VOICE\TEST.VOC)
  568. *
  569. *
  570. *
  571. * RETURNS: If successful, the SBSIM handle to extended memory will be
  572. *          returned.  (This handle will be used by FreeExtMem() to free
  573. *          the memory.)  If not successful, an SIMERR type will be
  574. *          returned.
  575. *
  576. *************************************************************************/
  577. SIMERR LoadExtMem(void far *Ptr)
  578. {
  579.   union REGS inregs, outregs;
  580.  
  581.   inregs.x.dx = FP_OFF(Ptr);
  582.   inregs.x.ax = FP_SEG(Ptr);    // Load DS register via AX register
  583.   asm {
  584.     mov ds, ax
  585.       }
  586.  
  587.   inregs.h.bh = 0;
  588.   inregs.h.bl = 16;
  589.   inregs.x.ax = 0;
  590.   inregs.x.cx = 0;  // Have driver assign you a handle (returned in AX)
  591.   int86(SIMint, &inregs, &outregs);
  592.  
  593.   return(outregs.x.ax);  // return extended mem. handle
  594. }
  595.  
  596. /*************************************************************************
  597. *
  598. *
  599. * FUNCTION: FreeExtMem() - Releases the memory in extended memory.
  600. *
  601. * DESCRIPTION: Pass the SBSIMHandle obtained by LoadExtMem() to this
  602. *              function.  The extended memory used by the LoadExtMem()
  603. *              will then be freed.
  604. *
  605. * RETURNS: 0 - (zero) if there are NO errors.  Otherwise a SIMERR type
  606. *              will be returned.
  607. *
  608. *************************************************************************/
  609. SIMERR FreeExtMem(int SBSIMHandle)
  610. {
  611.   union REGS inregs, outregs;
  612.  
  613.   inregs.h.bh = 0;
  614.   inregs.h.bl = 19;
  615.   inregs.x.ax = SBSIMHandle;
  616.   int86(SIMint, &inregs, &outregs);
  617.  
  618.   return(outregs.x.ax);  // return result
  619. }
  620.